﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.PreservedEntities.CUiPreservedObjectsCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.PreservedObjects;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.PreservedEntities;

public class CUiPreservedObjectsCmd : TxButtonCommand
{
  private CApPreservedObjectsEnabler m_enabler;

  public CUiPreservedObjectsCmd() => this.m_enabler = new CApPreservedObjectsEnabler(true);

  public virtual string Category => PreservedObjectsRes.CMD_CATEGORY;

  public virtual string Name => PreservedObjectsRes.PRES_CMD_NAME;

  public virtual string Tooltip => PreservedObjectsRes.PRES_CMD_TOOLTIP;

  public virtual string Bitmap => "Resources.PreserveEntity.bmp";

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("SetAsPreservedObjects");

  public virtual string Description => PreservedObjectsRes.PRES_CMD_DESCRIPTION;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual bool Licensed => TxCommandLicenser.SetAsPreservedObjects;

  public virtual void Execute(object cmdParams)
  {
    TxObjectList items = TxApplication.ActiveSelection.GetItems();
    if (((Collection<ITxObject>) items).Count < 1)
      return;
    TxApplication.ActiveUndoManager.StartTransaction();
    foreach (ITxDetailedRepresentation detailedRepresentation in (Collection<ITxObject>) items)
    {
      if (detailedRepresentation.CanPreserved() && !detailedRepresentation.Preserved)
        detailedRepresentation.Preserved = true;
    }
    if (((Collection<ITxObject>) items).Count == 1)
      TxApplication.ActiveSelection.SetItems(items);
    TxApplication.ActiveUndoManager.EndTransaction();
  }
}
